class Promise {
    // 构造器
    constructor(executor) {
        // 状态 默认为 pending 状态
        this.state = "pending";
        // 成功的值
        this.value = undefined;
        // 失败的原因
        this.reason = undefined;
        // resolve(value) 将状态改为 fulfilled 状态
        let resolve = value => {
            this.value = value;
            this.state = "fulfilled";
        }
        // reject(reason) 将状态改为 rejected 状态
        let reject = reason => {
            this.reason = reason;
            this.state = "rejected";
        }
        // 如果 executor 报错 立即执行 reject
        try {
            // 立即执行 executor 方法
            executor(resolve, reject);
        } catch (error) {
            reject(error);
        }
    }
    // then 方法
    then(onFulfilled, onRejected) {
        onFulfilled = onFulfilled instanceof Function ? onFulfilled : value => { value }
        onRejected = onRejected instanceof Function ? onRejected : error => { throw error }
        if (this.state == 'fulfilled') {
            setTimeout(() => {
                onFulfilled(this.value)
            });
        }else if(this.state = "rejected"){
            setTimeout(() => {
                onRejected(this.reason)
            });
        }
    }
    // catch 方法
    catch() { }
    // finall 方法
    finally() { }
}

Promise.resolve = () => { }
Promise.reject = () => { }
Promise.all = () => { }
Promise.allSettled = () => { }
Promise.race = () => { }

